import page from '../../databus/page';
import usersAddTpl from '../../views/users-add.art';
import {
  usersAddModel
} from '../../models/users-add';

//添加用户
export const addUser = () => {

  //渲染模板 继users.art 渲染之后再渲染
  $('#users-list-box').after(usersAddTpl());

  const _save = async () => {
    //提交表单
    const data = $('#users-from').serialize();

    //单击关闭模态框
    const $btnClose = $('#users-close');
    $btnClose.click();
    let result = await usersAddModel(data);
    if (result.ret) {
      page.setCurrentPage(1);
      //获取用户列表数据
      //告知list页面要重新渲染
      $('body').trigger('addUser');
    }
  }

  //点击模态框保存，提交表单
  $('#users-save').on('click', _save);


}